package com.washmadam.service.common.base;

import java.io.Serializable;

import com.alibaba.fastjson.JSON;
import com.washmadam.service.common.constants.Constant;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseDTO<T> implements Serializable {

    private static final long serialVersionUID = 2624508568735955502L;

    private String status;
    private String msg;
    private T data;

    public static String success() {
        return success(null);
    }

    public static String success(Object data) {
        return success(Constant.MSG_SUCCESS, data);
    }

    public static String success(String msg, Object data) {
        return toString(Constant.STATUS_SUCCESS, msg, data);
    }

    public static String fail() {
        return fail(null);
    }

    public static String fail(Object data) {
        return fail(Constant.MSG_FAIL, data);
    }

    public static String fail(String msg, Object data) {
        return toString(Constant.STATUS_FAIL, msg, data);
    }

    private static String toString(String code, String msg, Object data) {
        return JSON.toJSONStringWithDateFormat(new ResponseDTO(code, msg, data), "yyyy-MM-dd HH:mm:ss");
    }
    
    @Override
    public String toString() {
        return JSON.toJSONStringWithDateFormat(this, "yyyy-MM-dd HH:mm:ss");
    }

}
